package cn.sunan.org.service.impl;

import cn.sunan.basic.uitl.PageList;
import cn.sunan.org.domain.Department;
import cn.sunan.org.mapper.DepartmentMapper;
import cn.sunan.org.query.DepartmentQuery;
import cn.sunan.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public List<Department> selectAll() {
        return departmentMapper.selectAll();
    }

    @Override
    public Department selctById(Long id) {
        return departmentMapper.selctById(id);
    }

    @Override
    @Transactional
    public void save(Department department) {
        departmentMapper.save(department);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    public PageList<Department> queryByPage(DepartmentQuery query) {
        PageList<Department> list = new PageList<>();
        //查询当前页数具
        List<Department> rows = departmentMapper.selectpage(query);
        list.setRows(rows);
        //统计条数
        Long total = departmentMapper.count(query);
        list.setTotal(total);
        return list;
    }
}
